{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 引入程序中需要的模块。\n",
    "import numpy as np\n",
    "from bokeh.plotting import figure, output_file, show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "python 版本:3.10.2 | packaged by conda-forge | (main, Feb  1 2022, 19:27:13) [MSC v.1929 64 bit (AMD64)]\n",
      "Bokeh 版本:2.4.2\n"
     ]
    }
   ],
   "source": [
    "import bokeh\n",
    "import sys\n",
    "print('python 版本:{}'.format(sys.version))\n",
    "print('Bokeh 版本:{}'.format(bokeh.__version__))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将Bokeh生成的图插入jupyter notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1389\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  const force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  const JS_MIME_TYPE = 'application/javascript';\n",
       "  const HTML_MIME_TYPE = 'text/html';\n",
       "  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  const CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    const script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    const cell = handle.cell;\n",
       "\n",
       "    const id = cell.output_area._bokeh_element_id;\n",
       "    const server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd_clean, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            const id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd_destroy);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    const output_area = handle.output_area;\n",
       "    const output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      const bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      const script_attrs = bk_div.children[0].attributes;\n",
       "      for (let i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      const toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    const events = require('base/js/events');\n",
       "    const OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  const NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    const el = document.getElementById(\"1389\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error(url) {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < css_urls.length; i++) {\n",
       "      const url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < js_urls.length; i++) {\n",
       "      const url = js_urls[i];\n",
       "      const element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n",
       "  const css_urls = [];\n",
       "  \n",
       "\n",
       "  const inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (let i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      const cell = $(document.getElementById(\"1389\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    const el = document.getElementById(\"1389\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.2.min.js\"];\n  const css_urls = [];\n  \n\n  const inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(\"1389\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# output_file('plot.html')\n",
    "# 在Notebook中以内联的形式显示结果。\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备数据\n",
    "x = np.linspace(0, 2*np.pi, 50)\n",
    "y = np.sin(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "使用 **figure** 创建一个图示实例对象。figure 其实是 Bokeh 中的类 Figure 的简单封装，用于初始化图示对象，默认情况下会包含坐标系的坐标轴、坐标网格，以及图示右侧的有关工具等。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = figure(plot_width = 300, plot_height = 300, \n",
    "             title = 'sin line', \n",
    "             y_axis_label = 'y', \n",
    "             x_axis_label = 'x') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.renderers.GlyphRenderer\">GlyphRenderer</b>(</div><div style=\"display: table-cell;\">id&nbsp;=&nbsp;'1478', <span id=\"1494\" style=\"cursor: pointer;\">&hellip;)</span></div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">coordinates&nbsp;=&nbsp;None,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">data_source&nbsp;=&nbsp;ColumnDataSource(id='1474', ...),</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">glyph&nbsp;=&nbsp;Line(id='1475', ...),</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">group&nbsp;=&nbsp;None,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">hover_glyph&nbsp;=&nbsp;None,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">level&nbsp;=&nbsp;'glyph',</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">muted&nbsp;=&nbsp;False,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">muted_glyph&nbsp;=&nbsp;Line(id='1477', ...),</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name&nbsp;=&nbsp;None,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">nonselection_glyph&nbsp;=&nbsp;Line(id='1476', ...),</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">selection_glyph&nbsp;=&nbsp;'auto',</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events&nbsp;=&nbsp;[],</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">syncable&nbsp;=&nbsp;True,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags&nbsp;=&nbsp;[],</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">view&nbsp;=&nbsp;CDSView(id='1479', ...),</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">visible&nbsp;=&nbsp;True,</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">x_range_name&nbsp;=&nbsp;'default',</div></div><div class=\"1493\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">y_range_name&nbsp;=&nbsp;'default')</div></div></div>\n",
       "<script>\n",
       "(function() {\n",
       "  let expanded = false;\n",
       "  const ellipsis = document.getElementById(\"1494\");\n",
       "  ellipsis.addEventListener(\"click\", function() {\n",
       "    const rows = document.getElementsByClassName(\"1493\");\n",
       "    for (let i = 0; i < rows.length; i++) {\n",
       "      const el = rows[i];\n",
       "      el.style.display = expanded ? \"none\" : \"table-row\";\n",
       "    }\n",
       "    ellipsis.innerHTML = expanded ? \"&hellip;)\" : \"&lsaquo;&lsaquo;&lsaquo;\";\n",
       "    expanded = !expanded;\n",
       "  });\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "GlyphRenderer(id='1478', ...)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 调用了 fig 对象的一个方法 fig.line，意即绘制曲线。\n",
    "fig.line(x, y, line_width = 2, legend_label = 'sin')\n",
    "fig.line(x,np.cos(x),line_color='red',legend_label='cos')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"aeeaa03b-d2f0-46cc-a964-0321bb90e4d4\" data-root-id=\"1423\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"f5e50a67-4776-4743-82bb-a88a7658301b\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1434\"}],\"center\":[{\"id\":\"1437\"},{\"id\":\"1441\"},{\"id\":\"1472\"}],\"height\":300,\"left\":[{\"id\":\"1438\"}],\"renderers\":[{\"id\":\"1460\"},{\"id\":\"1478\"}],\"title\":{\"id\":\"1424\"},\"toolbar\":{\"id\":\"1449\"},\"width\":300,\"x_range\":{\"id\":\"1426\"},\"x_scale\":{\"id\":\"1430\"},\"y_range\":{\"id\":\"1428\"},\"y_scale\":{\"id\":\"1432\"}},\"id\":\"1423\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1435\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1447\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1470\",\"type\":\"Selection\"},{\"attributes\":{\"label\":{\"value\":\"cos\"},\"renderers\":[{\"id\":\"1478\"}]},\"id\":\"1492\",\"type\":\"LegendItem\"},{\"attributes\":{\"source\":{\"id\":\"1456\"}},\"id\":\"1461\",\"type\":\"CDSView\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1459\",\"type\":\"Line\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1474\"},\"glyph\":{\"id\":\"1475\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1477\"},\"nonselection_glyph\":{\"id\":\"1476\"},\"view\":{\"id\":\"1479\"}},\"id\":\"1478\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1464\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1477\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1446\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1490\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1428\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1467\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1442\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1432\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1426\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis_label\":\"y\",\"coordinates\":null,\"formatter\":{\"id\":\"1464\"},\"group\":null,\"major_label_policy\":{\"id\":\"1465\"},\"ticker\":{\"id\":\"1439\"}},\"id\":\"1438\",\"type\":\"LinearAxis\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1456\"},\"glyph\":{\"id\":\"1457\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1459\"},\"nonselection_glyph\":{\"id\":\"1458\"},\"view\":{\"id\":\"1461\"}},\"id\":\"1460\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1457\",\"type\":\"Line\"},{\"attributes\":{\"overlay\":{\"id\":\"1448\"}},\"id\":\"1444\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1438\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1441\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1465\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1448\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"source\":{\"id\":\"1474\"}},\"id\":\"1479\",\"type\":\"CDSView\"},{\"attributes\":{\"tools\":[{\"id\":\"1442\"},{\"id\":\"1443\"},{\"id\":\"1444\"},{\"id\":\"1445\"},{\"id\":\"1446\"},{\"id\":\"1447\"}]},\"id\":\"1449\",\"type\":\"Toolbar\"},{\"attributes\":{\"data\":{\"x\":{\"__ndarray__\":\"AAAAAAAAAACSN2u0yGnAP5I3a7TIadA/W9OgDq2e2D+SN2u0yGngP3YFhuE6hOQ/W9OgDq2e6D9Aobs7H7nsP5I3a7TIafA/hJ74ygF38j92BYbhOoT0P2lsE/hzkfY/W9OgDq2e+D9NOi4l5qv6P0Chuzsfufw/MghJUljG/j+SN2u0yGkAQAvrsT9lcAFAhJ74ygF3AkD9UT9Wnn0DQHYFhuE6hARA8LjMbNeKBUBpbBP4c5EGQOIfWoMQmAdAW9OgDq2eCEDUhueZSaUJQE06LiXmqwpAxu10sIKyC0BAobs7H7kMQLlUAse7vw1AMghJUljGDkCru4/d9MwPQJI3a7TIaRBAT5EO+hbtEEAL67E/ZXARQMhEVYWz8xFAhJ74ygF3EkBB+JsQUPoSQP1RP1aefRNAuqvim+wAFEB2BYbhOoQUQDNfKSeJBxVA8LjMbNeKFUCsEnCyJQ4WQGlsE/hzkRZAJca2PcIUF0DiH1qDEJgXQJ55/cheGxhAW9OgDq2eGEAYLURU+yEZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]},\"y\":{\"__ndarray__\":\"AAAAAAAAAACPjathR17AP+7Ll2/gO9A/3WJO5l8E2D+ihluX6mffP6NL+7G4I+M/w6xnDQhD5j9L3gV1wwTpP/qbEFtUXes/NeHcQt5C7T+Um5A0aK3uP8YaX0D+lu8/yk9shMr77z8goCdMJdrvP2npWAWcMu8/zQmh7e4H7j//5zCCBV/sP42TUuLZPuo/MmFse1uw5z+478V5Sb7kPyrU8JsFdeE/w6txTcDE2z/AL8eouyrUP+NvT83id8g/3fV26+dmsD+s9Xbr52awv8tvT83id8i/tC/HqLsq1L+/q3FNwMTbvyXU8JsFdeG/s+/FeUm+5L8uYWx7W7Dnv4qTUuLZPuq//ucwggVf7L/LCaHt7gfuv2npWAWcMu+/H6AnTCXa77/KT2yEyvvvv8gaX0D+lu+/lpuQNGit7r854dxC3kLtv/2bEFtUXeu/TN4FdcME6b/IrGcNCEPmv6ZL+7G4I+O/sIZbl+pn37/mYk7mXwTYvwDMl2/gO9C/po2rYUdewL8HXBQzJqaxvA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]}},\"selected\":{\"id\":\"1470\"},\"selection_policy\":{\"id\":\"1469\"}},\"id\":\"1456\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1430\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1489\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"1434\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1437\",\"type\":\"Grid\"},{\"attributes\":{\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1475\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1458\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1443\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"1473\"},{\"id\":\"1492\"}]},\"id\":\"1472\",\"type\":\"Legend\"},{\"attributes\":{\"label\":{\"value\":\"sin\"},\"renderers\":[{\"id\":\"1460\"}]},\"id\":\"1473\",\"type\":\"LegendItem\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"sin line\"},\"id\":\"1424\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1439\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1468\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis_label\":\"x\",\"coordinates\":null,\"formatter\":{\"id\":\"1467\"},\"group\":null,\"major_label_policy\":{\"id\":\"1468\"},\"ticker\":{\"id\":\"1435\"}},\"id\":\"1434\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1476\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1469\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data\":{\"x\":{\"__ndarray__\":\"AAAAAAAAAACSN2u0yGnAP5I3a7TIadA/W9OgDq2e2D+SN2u0yGngP3YFhuE6hOQ/W9OgDq2e6D9Aobs7H7nsP5I3a7TIafA/hJ74ygF38j92BYbhOoT0P2lsE/hzkfY/W9OgDq2e+D9NOi4l5qv6P0Chuzsfufw/MghJUljG/j+SN2u0yGkAQAvrsT9lcAFAhJ74ygF3AkD9UT9Wnn0DQHYFhuE6hARA8LjMbNeKBUBpbBP4c5EGQOIfWoMQmAdAW9OgDq2eCEDUhueZSaUJQE06LiXmqwpAxu10sIKyC0BAobs7H7kMQLlUAse7vw1AMghJUljGDkCru4/d9MwPQJI3a7TIaRBAT5EO+hbtEEAL67E/ZXARQMhEVYWz8xFAhJ74ygF3EkBB+JsQUPoSQP1RP1aefRNAuqvim+wAFEB2BYbhOoQUQDNfKSeJBxVA8LjMbNeKFUCsEnCyJQ4WQGlsE/hzkRZAJca2PcIUF0DiH1qDEJgXQJ55/cheGxhAW9OgDq2eGEAYLURU+yEZQA==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]},\"y\":{\"__ndarray__\":\"AAAAAAAA8D/t2DtpvrzvPwDtSlsU9O4/CEzdVE2p7T9ATFPD1+HrP7O8Dy4upek/Gbm4xrf85j/S7YvioPPjP8dC7AKsluA/VUcrZfjn2T9F99gxszXSP8uDzvTEbcQ/8DLpehBpoD9hu+8L95S4v4BFAuOQe8y//u16B3Ya1r9t224zOprdvz4WF5nHTuK/LM8XKH2D5b/mvBvqw13ov5OqNSWe0eq/cFzLqbzU7L/Gu28oql7uv+i1y7/uaO+/bM8hLSvv779szyEtK+/vv+m1y7/uaO+/yLtvKKpe7r9xXMupvNTsv5aqNSWe0eq/6rwb6sNd6L8wzxcofYPlv0MWF5nHTuK/cdtuMzqa3b8K7noHdhrWv4lFAuOQe8y/orvvC/eUuL+sMul6EGmgP6qDzvTEbcQ/OffYMbM10j9CRytl+OfZP8FC7AKsluA/0O2L4qDz4z8TubjGt/zmP7C8Dy4upek/PExTw9fh6z8HTN1UTantP/3sSlsU9O4/7Ng7ab687z8AAAAAAADwPw==\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[50]}},\"selected\":{\"id\":\"1490\"},\"selection_policy\":{\"id\":\"1489\"}},\"id\":\"1474\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1445\",\"type\":\"SaveTool\"}],\"root_ids\":[\"1423\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"f5e50a67-4776-4743-82bb-a88a7658301b\",\"root_ids\":[\"1423\"],\"roots\":{\"1423\":\"aeeaa03b-d2f0-46cc-a964-0321bb90e4d4\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1423"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 要显示所绘制的图示对象。\n",
    "show(fig)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"4225a181-0a93-4e2c-8b49-54e9c6602b5a\" data-root-id=\"1601\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"e2ef74a8-481f-454e-8fb9-ccfc6f331752\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1610\"}],\"center\":[{\"id\":\"1613\"},{\"id\":\"1617\"}],\"height\":300,\"left\":[{\"id\":\"1614\"}],\"renderers\":[{\"id\":\"1636\"}],\"title\":{\"id\":\"1684\"},\"toolbar\":{\"id\":\"1625\"},\"width\":300,\"x_range\":{\"id\":\"1602\"},\"x_scale\":{\"id\":\"1606\"},\"y_range\":{\"id\":\"1604\"},\"y_scale\":{\"id\":\"1608\"}},\"id\":\"1601\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1622\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1621\",\"type\":\"SaveTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1624\"}},\"id\":\"1620\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"tools\":[{\"id\":\"1618\"},{\"id\":\"1619\"},{\"id\":\"1620\"},{\"id\":\"1621\"},{\"id\":\"1622\"},{\"id\":\"1623\"}]},\"id\":\"1625\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1618\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1619\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1692\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1615\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1614\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1617\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1687\"},\"group\":null,\"major_label_policy\":{\"id\":\"1688\"},\"ticker\":{\"id\":\"1615\"}},\"id\":\"1614\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1623\",\"type\":\"HelpTool\"},{\"attributes\":{\"data\":{\"x\":[0,1,2,3,4],\"y\":[0,1,2,3,4]},\"selected\":{\"id\":\"1693\"},\"selection_policy\":{\"id\":\"1692\"}},\"id\":\"1632\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1611\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1691\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1608\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1604\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1602\",\"type\":\"DataRange1d\"},{\"attributes\":{\"source\":{\"id\":\"1632\"}},\"id\":\"1637\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1606\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1690\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1693\",\"type\":\"Selection\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1632\"},\"glyph\":{\"id\":\"1633\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1635\"},\"nonselection_glyph\":{\"id\":\"1634\"},\"view\":{\"id\":\"1637\"}},\"id\":\"1636\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1687\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1684\",\"type\":\"Title\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1634\",\"type\":\"Line\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1633\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1688\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1624\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1635\",\"type\":\"Line\"},{\"attributes\":{\"axis\":{\"id\":\"1610\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1613\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1690\"},\"group\":null,\"major_label_policy\":{\"id\":\"1691\"},\"ticker\":{\"id\":\"1611\"}},\"id\":\"1610\",\"type\":\"LinearAxis\"}],\"root_ids\":[\"1601\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"e2ef74a8-481f-454e-8fb9-ccfc6f331752\",\"root_ids\":[\"1601\"],\"roots\":{\"1601\":\"4225a181-0a93-4e2c-8b49-54e9c6602b5a\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1601"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "p = figure(width=300, height=300)\n",
    "p.line(range(5), range(5))\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"16777d7a-3100-447a-b7f6-201870c9e81f\" data-root-id=\"1750\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"41a3f3a3-baa7-4a14-94ab-44bb004dd49a\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1759\"}],\"center\":[{\"id\":\"1762\"},{\"id\":\"1766\"}],\"height\":300,\"left\":[{\"id\":\"1763\"}],\"renderers\":[{\"id\":\"1785\"}],\"title\":{\"id\":\"1844\"},\"toolbar\":{\"id\":\"1774\"},\"width\":300,\"x_range\":{\"id\":\"1751\"},\"x_scale\":{\"id\":\"1755\"},\"y_range\":{\"id\":\"1753\"},\"y_scale\":{\"id\":\"1757\"}},\"id\":\"1750\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1852\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1753\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1782\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1847\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data\":{\"x\":[1,2,3],\"y\":[3,4,3]},\"selected\":{\"id\":\"1853\"},\"selection_policy\":{\"id\":\"1852\"}},\"id\":\"1781\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1850\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1768\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1772\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1851\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1770\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1771\",\"type\":\"ResetTool\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1781\"},\"glyph\":{\"id\":\"1782\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1784\"},\"nonselection_glyph\":{\"id\":\"1783\"},\"view\":{\"id\":\"1786\"}},\"id\":\"1785\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1751\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1784\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1848\",\"type\":\"AllLabels\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1783\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1760\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1781\"}},\"id\":\"1786\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1763\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1766\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1767\",\"type\":\"PanTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1773\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"1773\"}},\"id\":\"1769\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1759\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1762\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1755\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1847\"},\"group\":null,\"major_label_policy\":{\"id\":\"1848\"},\"ticker\":{\"id\":\"1764\"}},\"id\":\"1763\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1764\",\"type\":\"BasicTicker\"},{\"attributes\":{\"tools\":[{\"id\":\"1767\"},{\"id\":\"1768\"},{\"id\":\"1769\"},{\"id\":\"1770\"},{\"id\":\"1771\"},{\"id\":\"1772\"}]},\"id\":\"1774\",\"type\":\"Toolbar\"},{\"attributes\":{\"coordinates\":null,\"group\":null},\"id\":\"1844\",\"type\":\"Title\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1850\"},\"group\":null,\"major_label_policy\":{\"id\":\"1851\"},\"ticker\":{\"id\":\"1760\"}},\"id\":\"1759\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1853\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1757\",\"type\":\"LinearScale\"}],\"root_ids\":[\"1750\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.2\"}};\n",
       "  const render_items = [{\"docid\":\"41a3f3a3-baa7-4a14-94ab-44bb004dd49a\",\"root_ids\":[\"1750\"],\"roots\":{\"1750\":\"16777d7a-3100-447a-b7f6-201870c9e81f\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1750"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot = figure(width=300, height=300,)\n",
    "plot.circle([1,2,3], [3,4,3])\n",
    "show(plot)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "下一个output_notebook或output_file调用之前的reset_output()至少在版本0.10.0中有效。\n",
    "##### cell 1\n",
    "from bokeh.plotting import figure, show, output_notebook, output_file, reset_output\n",
    "p = figure(width=300, height=300)\n",
    "p.line(range(5), range(5))\n",
    "output_notebook()\n",
    "show(p)\n",
    "\n",
    "##### cell 2\n",
    "reset_output()\n",
    "output_file('foo.html')\n",
    "show(p)\n",
    "\n",
    "###### cell 3\n",
    "reset_output()\n",
    "output_notebook()\n",
    "show(p)\n",
    "\n",
    "第一个和第三个显示在笔记本中，第二个显示在浏览器中。在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
